package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.FoundGoodTitleBeen;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;

/**
 * @author gzk
 * @date 2020/4/13 0013
 * description： 发现好货
 */
public class HomeMarketGoodTitleAdapter extends RecyclerView.Adapter<HomeMarketGoodTitleAdapter.MyViewHolder> {

    public ItemClickListener mItemClickListener;
    private List<FoundGoodTitleBeen.DataBean> list = new ArrayList<>();
    private Context context;
    private String select_id="";


    public HomeMarketGoodTitleAdapter(Context context, List<FoundGoodTitleBeen.DataBean> list ) {
        this.list = list;
        this.context = context;

    }

    public void setSelect_id(String select_id){
        this.select_id = select_id;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_found_good_title, parent, false);
        MyViewHolder myHolder = new MyViewHolder(inflate);

        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, final int position) {



        holder.tvTitle.setText(list.get(position).getName());
        if (select_id.equals(list.get(position).getId()+"")){
            holder.tvTitle.setTextColor(context.getResources().getColor(R.color.color_FFFFFF));
            holder.tvTitle.setBackgroundResource(R.drawable.add_address_select);
        }else {
            holder.tvTitle.setTextColor(context.getResources().getColor(R.color.color_333333));
            holder.tvTitle.setBackgroundResource(R.drawable.df8f8f8_r4);
        }

        holder.tvTitle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (mItemClickListener != null) {
                    mItemClickListener.onItemClick(position);
                }
            }
        });
    }


    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_title)
        TextView tvTitle;


        public MyViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


    public void setOnItemClickListener(ItemClickListener itemClickListener) {
        this.mItemClickListener = itemClickListener;

    }

}
